home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snpd1292.zip / KILLFF.C < prev    next >
C/C++ Source or Header  |  1992-12-26  |  4KB  |  95 lines

  1. /*
  2. ** This program was written to strip out all the Form Feeds in text
  3. ** files. I hate it when people waste my printer paper! I also like
  4. ** to post News Letters for my Users on my BBS, and imbedded Form
  5. ** Feeds screw things up bad when trying to view the News Letters
  6. ** (like FIDONEWS!) Hope you like it!
  7. **
  8. ** KILL FORM FEEDS v1.1 by Jerry Gore (Public domain?)
  9. ** Version 1.2 by Erik VanRiper on 12/22/91 Public Domain!
  10. **
  11. ** This is basically a complete re-write.
  12. **
  13. ** Reads a text file and makes a duplicate with NO Form Feed
  14. ** characters! The duplicates name will default to temp.txt. Form
  15. ** Feed characters are replaced with a space (decimal 32).
  16. **
  17. ** Usage: KILLFF FILE.TXT [TEMP.TXT]
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23.  
  24. #define BUFSIZE 32768
  25.  
  26. main(int argc, char *argv[])
  27. {
  28.    FILE *in, *out;              /* input and output files        */
  29.    char name[80],               /* name of file to be fixed      */
  30.         temp[80] = "temp.txt",  /* output file name              */
  31.         *buf,                   /* buffer we will use to write   */
  32.         *s;                     /* searching pointer             */
  33.    unsigned int bad,            /* check to see if write ok      */
  34.                 num;            /* number of bytes read          */
  35.  
  36.    printf("\nKILL FORM FEEDS v1.1 by Jerry Gore");
  37.    printf("\nRevised by Erik VanRiper (v1.2)\n\n");
  38.  
  39.    if(argc < 2)                              /* usage info       */
  40.    {
  41.       printf("Usage:\n\tKILLFF input_file [output_file]\n");
  42.       return(0);                             /* return to OS     */
  43.    }
  44.  
  45.    strcpy(name,argv[1]);                     /* input filename   */
  46.    if(argc == 3) strcpy(temp,argv[2]);       /* outfile name     */
  47.  
  48.    if((buf = calloc(BUFSIZE, 1)) == NULL)/* malloc a large buffer  */
  49.    {
  50.       printf("\nOut of memory.  :-(\n");
  51.       return(0);                             /* return to OS     */
  52.    }
  53.    if((in = fopen(name,"r")) == NULL)        /* Open in file     */
  54.    {
  55.       printf("\nCan't Open Input File %s!",name);
  56.       free(buf);                             /* free memory      */
  57.       return(0);                             /* return to OS     */
  58.    }
  59.    if((out = fopen(temp,"wt")) == NULL)      /* open out file    */
  60.    {
  61.       printf("\nCan't Open File %s",temp);
  62.       fclose(in);                            /* close in file    */
  63.       free(buf);                             /* free memory      */
  64.       return(0);                             /* return to OS     */
  65.    }
  66.  
  67.    printf("Input file: %s Output file: %s\n",name,temp);
  68.  
  69.    /* read in file while chars to read */
  70.  
  71.    num = fread(buf,sizeof(char *),BUFSIZE-1,in);
  72.    buf[num] = '\0';
  73.    while(num > 0)
  74.    {
  75.       while((s = strchr(buf, '\x0C')) != NULL) /* look for FF    */
  76.          *s = '\x20';                        /* change to space  */
  77.  
  78.       bad=fwrite(buf,sizeof(char *),num,out); /* write out buf   */
  79.       if(bad != num)                         /* error            */
  80.       {
  81.          printf("\nCan't Write to %s ", temp);
  82.          fclose(in);                         /* close in file    */
  83.          fclose(out);                        /* close out file   */
  84.          free(buf);                          /* free memory      */
  85.          return(0);                          /* return to OS     */
  86.       }
  87.       num = fread(buf,sizeof(char *),31999,in); /* read in more  */
  88.    }
  89.    fclose(in);                               /* close in file    */
  90.    fclose(out);                              /* close out file   */
  91.    free(buf);                                /* free memory      */
  92.    printf("\nDone!");                        /* Finished         */
  93.    return(1);                                /* return to OS     */
  94. }
  95.